package com.woniuxy.profile.service.impl;

import com.woniuxy.commons.dto.IntegralDto;
import com.woniuxy.commons.entity.Integral;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.profile.mapper.IntegralMapper;
import com.woniuxy.profile.service.IntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: dengzj
 * @Description:
 * @Date: Created in 15:06 2020/8/1
 */
@Service
public class IntegralServiceImpl implements IntegralService {

    @Autowired
    private IntegralMapper integralMapper;
    @Override
    public PageBean<Integral> findIntegralByUid(IntegralDto integralDto, int page) {
        PageBean<Integral> integralPageBean=new PageBean<>();
        int index=(page-1)*8;
        integralDto.setIndex(index).setPageSize(8);
        List<Integral> data=integralMapper.findIntegralByUid(integralDto);
        int totalNum=integralMapper.countOfIntegral(integralDto.getUid());
        integralPageBean.setData(data);
        integralPageBean.setTotalNum(totalNum);
        integralPageBean.setTotalPage(totalNum % 8 == 0 ? totalNum / 8 : totalNum / 8 + 1);
        integralPageBean.setNumsOfCurrPage(data.size());
        integralPageBean.setPage(page);
        integralPageBean.setPageSize(8);
        return integralPageBean;
    }

    @Override
    public int totalIntegral(int uid) {
        return 0;
    }

    @Override
    public List<Integral> rankingIntegral(IntegralDto integralDto) {

        return integralMapper.rankingIntegral(integralDto);
    }
}
